import { 
    GET_LIST,
    DEL_LIST,
    AJAX_SEND
} from '../../action/home'

import Immutable from "immutable";


const initialState = Immutable.fromJS({
  msg: '',
  action_state: '',
  getResult: []
});

//reducer其实也是个方法而已,参数是state和action,返回值是新的state
export default function home(state = initialState, action = {}) {
  switch (action.type) {
    case GET_LIST: {
      state = state.set('action_state',GET_LIST);
      state = state.set('getResult',action.payload);
      break;
    }
    case DEL_LIST: {
      let list = state.get('getResult');
      let newList = list.filter((val,i) => {
        return val['key'] != action.meta['Id'];
      });
      state = state.set('getResult',newList);
    }
    case AJAX_SEND: {
      let res = action.payload;
    }
    default: {
      return state
    }
  }
  
  return state;
}